<?php
class ViewRender{
	private $_controller;
	private $_action;
	private $_viewType;
	private $_viewpath;
	private $_layoutName;
	protected $_hasView;
	protected $_hasLayout;
	private $_layoutPath;
	public $objectData;
	public $relativeData;
	public $title;
	public function __construct($controller = null,$action = null, $viewType = null){
		$this->_controller = $controller;
		$this->_action = $action;
		$this->_viewType = $viewType;
		$this->_layoutName = Config::LAYOUT_DEFAULT;
		$this->_hasView = true;
		$this->_hasLayout = true;
	}
	public function render(){
		$this->_viewpath = Config::VIEW_FOLDER 
		. Config::SLASH 
		. $this->_controller
		. Config::SLASH
		. $this->_action
		. Config::SLASH
		. $this->_viewType.'.php';
		$this->_layoutPath = Config::LAYOUT_FOLDER
		. Config::SLASH
		. $this->_layoutName
		. Config::SLASH
		. 'index.php';
		if(!file_exists($this->_viewpath)){
			$this->_viewpath = Config::VIEW_FOLDER
			. Config::SLASH
			. Config::VIEW_DEFAULT_CONTROLLER
			. Config::SLASH
			. $this->_action
			. Config::SLASH
			. $this->_viewType.'.php';
		}
		if($this->_hasLayout){
			require_once $this->_layoutPath;
		}
		else{
			if($this->_hasView)
				require_once $this->_viewpath;
		}
	}
	public function content(){
		require_once $this->_viewpath;
	}
	public function block($blockname){
		require_once BLOCK_PATH . '/'.$blockname.'.php';
	}
	/**
	 * @return the $_layoutName
	 */
	public function getLayoutName() {
		return $this->_layoutName;
	}

	/**
	 * @param string $_layoutName
	 */
	public function setLayoutName($_layoutName) {
		$this->_layoutName = $_layoutName;
	}
	/**
	 * @param boolean $_hasLayout
	 */
	public function setHasLayout($_hasLayout) {
		$this->_hasLayout = $_hasLayout;
	}
	/**
	 * @param boolean $_hasView
	 */
	public function setHasView($_hasView) {
		$this->_hasView = $_hasView;
	}
	public function bind($key){
		return isset($this->objectData[$key])?$this->objectData[$key]:'';
	}
	
}